<template>
  <el-dialog
    class="dialog"
    title="客户选择"
    width="950px"
    :visible.sync="dialog.visible"
    :append-to-body="true"
  >
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true">
      <el-form-item label="案件编号" prop="caseNo">
        <el-input
          v-model="queryParams.caseNo"
          placeholder="案件编号"
          clearable
          style="width: 150px"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item label="案件名称" prop="caseName">
        <el-input
          v-model="queryParams.caseName"
          placeholder="案件名称"
          clearable
          style="width: 150px"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="客户名称" prop="customerName">
        <el-input
          v-model="queryParams.customerName"
          placeholder="客户名称"
          clearable
          style="width: 150px"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="承办人" prop="customerName">
        <el-input
          v-model="queryParams.handlerName"
          placeholder="承办人"
          clearable
          style="width: 150px"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="案件分类" prop="categoryId">
        <el-select
          clearable
          v-model="queryParams.categoryId"
          placeholder="请选择案件分类"
        >
          <el-option
            :label="item.label"
            :value="item.value"
            v-for="(item, index) of dict.type.sys_carage_type"
            :key="index + 'Source'"
          ></el-option>
        </el-select>
      </el-form-item>

      <el-form-item label="案件状态" prop="status">
        <el-select
          v-model="queryParams.status"
          placeholder="案件状态"
          clearable
        >
          <el-option
            :label="item.label"
            :value="item.value"
            v-for="(item, index) of dict.type.case_state"
            :key="index + 'status'"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="审批状态" prop="status">
        <el-select
          v-model="queryParams.auditStatus"
          placeholder="审批状态"
          clearable
        >
          <el-option
            :label="item.label"
            :value="item.value"
            v-for="(item, index) of dict.type.audit_status"
            :key="index + 'status'"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          >搜索
        </el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置
        </el-button>
      </el-form-item>
    </el-form>
    <el-table
      v-loading="loading"
      :data="roleList"
      height="400"
      highlight-current-row
      @current-change="handleCurrentChange"
    >
      <el-table-column
        label="案件编号"
        prop="caseNo"
        min-width="240"
        :show-overflow-tooltip="true"
      />
      <el-table-column
        label="案件名称"
        prop="caseName"
        :show-overflow-tooltip="true"
        width="150"
      >
        <template slot-scope="scope">
          <div>
            {{ scope.row.caseName }}
          </div>
        </template>
      </el-table-column>
      <el-table-column
        label="案件分类"
        prop="status"
        width="150"
        :show-overflow-tooltip="true"
      >
        <template slot-scope="scope">
          {{ scope.row.categoryName
          }}{{
            scope.row.subCategoryName ? ">>" + scope.row.subCategoryName : ""
          }}
          {{
            scope.row.thirdCategoryName
              ? ">>" + scope.row.thirdCategoryName
              : ""
          }}
        </template>
      </el-table-column>
      <el-table-column
        label="收案时间"
        :show-overflow-tooltip="true"
        width="150"
        prop="receiptDate"
      />
      <el-table-column
        label="客户"
        :show-overflow-tooltip="true"
        width="150"
        prop="customerName"
      />
      <el-table-column
        label="对方当事人"
        :show-overflow-tooltip="true"
        width="150"
        prop="targetPartyName"
      />
      <el-table-column
        label="承办人员"
        :show-overflow-tooltip="true"
        width="150"
        prop="handlerName"
      />

      <el-table-column
        label="受理机构"
        :show-overflow-tooltip="true"
        prop="acceptOrgName"
        width="150"
      />
      <el-table-column
        label="受理案号"
        :show-overflow-tooltip="true"
        prop="acceptOrgNo"
        width="150"
      />
      <el-table-column
        label="案件状态"
        :show-overflow-tooltip="true"
        prop="roleSort"
        width="150"
      >
        <template slot-scope="scope">
          <dict-tag :options="dict.type.case_state" :value="scope.row.status" />
        </template>
      </el-table-column>
      <el-table-column label="审批结果" prop="auditStatus">
        <template slot-scope="scope">
          <dict-tag
            :options="dict.type.audit_status"
            :value="scope.row.auditStatus"
          />
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
    <div class="foot">
      <el-button type="primary" @click="submitForm('queryForm')"
        >确定</el-button
      >
      <el-button @click="resetForm('queryForm')">取消</el-button>
    </div>
  </el-dialog>
</template>

<script>
import { listRole, delRole } from "@/api/system/role";
import { caselist } from "@/api/case/case";
export default {
  components: {},
  dicts: [
    "sys_normal_disable",
    "case_source",
    "approval_status",
    "case_state",
    "audit_status",
    "sys_carage_type",
  ],
  data() {
    return {
      dialog: {
        visible: false,
        title: "客户选择",
      },
      options: [{ value: 1, label: "正常" }],
      roleList: [], //表格数组
      total: 1,
      loading: false,
      current: null,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        caseNo: undefined,
        caseName: undefined,
        customerName: undefined,
        handlerName: "",
        categoryId: "",
        status: "",
        auditStatus: "",
        orderByColumn: "updateTime",
        isAsc: "desc",
      },
    };
  },
  computed: {},
  methods: {
    //打开弹窗
    async open() {
      this.getList();
      this.current = null;
      this.dialog.visible = true;
    },
    /** 查询角色列表 */
    getList() {
      this.loading = true;
      let params = {
        orderByColumn: "updateTime",
        isAsc: "desc",

        auditor: 0,
        proveType: 0,
      };
      this.multipleSelection = [];
      caselist({
        ...this.addDateRange(this.queryParams, this.dateRange),
        ...params,
      }).then((response) => {
        this.roleList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.roleList = [];
      this.$refs["queryForm"].resetFields();
      this.handleQuery();
    },
    // //选择客户
    // handleSelectionChange(val) {
    //   console.log(val);
    //   this.current = val;
    // },
    handleCurrentChange(val) {
      console.log(val);
      this.current = val;
    },
    submitForm(formName) {
      if (this.current) {
        this.resetForm("queryForm");
        console.log("提交成功");
        this.$emit("submit", this.current);
      } else {
        this.$message.warning("请先选择数据！");
      }
    },
    resetForm(formName) {
      this.$refs[formName].resetFields();
      this.dialog.visible = false;
    },
  },
};
</script>

<style lang="scss" scoped>
.foot {
  text-align: center;
  margin-top: 50px;
}
.header {
  margin: 20px;
}
::v-deep .w150.el-input.el-input--small.el-input--suffix {
  width: 150px;
}
::v-deep .el-select.w150.el-select--small {
  width: 150px;
}
::v-deep .pagination-container .el-pagination {
  position: relative;
  left: 0;
  right: 0;
  text-align: center;
}
::v-deep .el-dialog__body {
  display: flex;
  justify-content: space-between;
  flex-direction: column;
  padding: 20px;
}
::v-deep .el-table__body-wrapper.is-scrolling-none {
  min-height: 130px !important;
  height: calc(100vh - 570px) !important;
}
::v-deep .el-table__body-wrapper.is-scrolling-left {
  height: 300px !important;
}
</style>
